package com.ibm.mall.base;

import java.lang.reflect.ParameterizedType;

import javax.annotation.Resource;

import com.ibm.mall.model.User;
import com.ibm.mall.service.AdministratorService;
import com.ibm.mall.service.AppraisalService;
import com.ibm.mall.service.CommodityClassService;
import com.ibm.mall.service.OrderFormService;
import com.ibm.mall.service.OrderListService;
import com.ibm.mall.service.ShippingAddressService;
import com.ibm.mall.service.FeedbackService;
import com.ibm.mall.service.CommodityService;
import com.ibm.mall.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T> {

	// =============== ModelDriven==================

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected T model;

	public BaseAction() {
		try {
			// 
			ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
			@SuppressWarnings("unchecked")
			Class<T> clazz = (Class<T>) pt.getActualTypeArguments()[0];
			// 
			model = clazz.newInstance();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public T getModel() {
		return model;
	}

	// =============== Service==================
	@Resource
	protected UserService userService;
	
	@Resource
	protected FeedbackService feedbackService;
	
	@Resource
	protected CommodityService commodityService;
	
	@Resource
	protected CommodityClassService commodityClassService;
	
	@Resource
	protected AppraisalService appraisalService;
	
	@Resource
	protected ShippingAddressService shippingAddressService;
	
	@Resource
	protected OrderFormService orderFormService;
	
	@Resource
	protected OrderListService orderListService;
	
	@Resource
	protected AdministratorService administratorService;

	/**
	 * 
	 * 
	 * @return
	 */
	protected User getCurrentUser() {
		return (User) ActionContext.getContext().getSession().get("user");
	}

	// ==============  =============

	protected int page = 1; // 
	protected int rows = 10; // 

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

}
